package com.tanhua.server.interceptor;

import com.tanhua.model.domain.User;

/**
 * 工具类，实现向ThreadLocal存储数据的方法
 */
public class UserHolder {
    private static ThreadLocal<User> threadLocal=new ThreadLocal<>();
    //将用户对象，存入ThreadLocal
    public static void setUser(User user){
        threadLocal.set(user);
    }
    //从当前线程，获取用户对象
    public static User getUser(){
        return threadLocal.get();
    }
    //从当前线程，获取用户对象的id
    public static Long getId(){
        return threadLocal.get().getId();
    }
    //从当前线程，获取用户对象的手机号码
    public static String getMobile(){
        return threadLocal.get().getMobile();
    }
    //清空
    public static void remove(){
        threadLocal.remove();
    }
}
